package org.cytoscape.myapp.cytoscape_app_v1.internal.tasks.groups;


import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.aggregation.Aggregation;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.aggregation.AggregationListString;
import org.cytoscape.myapp.cytoscape_app_v1.internal.helpers.ColumnListEnum;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;


public class GroupsAggregationTask implements  Task{
	 
	private CyApplicationManager applicationManager;
	private CyGroupManager groupManager;	
	
	


	public GroupsAggregationTask(CyApplicationManager applicationManager,
			CyGroupManager groupManager) {
		super();
		this.applicationManager = applicationManager;
		this.groupManager = groupManager;
	}


	public void run(TaskMonitor taskMonitor) throws Exception {
			
		CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
		Set<CyGroup> groups = this.groupManager.getGroupSet(cyNetwork);
		Aggregation aggregation = new AggregationListString(cyNetwork);
		for (CyGroup cyGroup : groups) {
			for (ColumnListEnum column : ColumnListEnum.values()) {
				cyNetwork.getDefaultNodeTable()
						.getRow(cyGroup.getGroupNode().getSUID())
						.set(column.toString(), (List<String>)aggregation.getAggregation(column.toString(), cyGroup.getNodeList()));
			}
				
		}

	}


	public void cancel() {
		
		
	}

}
